<?php
// 本类由系统自动生成，仅供测试用途
class ChongzhiAction extends CommonAction {
	   
    public function  index(){
        if (IS_POST) {
             $user=$_POST['name'];
             switch ($_POST['buytype']){
                 case 1:$field='xnb'; break;
                 case 2:$field='ks'; break;
                 case 3:$field='rmb'; break;
             }
             if(M('User')->where("username='$user'")->setInc($field,$_POST['money'])){
                 $czuser=M("User")->where("username='$user'")->find();
                 
                 $data['uid']=$czuser['id'];
                 $data['type']=$field;
                 $data['add_time']=time();
                 $data['money']=$_POST['money'];
                M("Chongzhi")->add($data);
                 $this->success('充值成功');
             }else {
                 $this->error('充值失败');
             }
        }else {
           $sys= M("Sys")->find();
           $kgname=$sys['kgname'];
//                 $r=array(array('id'=>'1','name'=>'TMC'),array('id'=>2,'name'=>'TG'),array('id'=>3,'name'=>'RMB'));
                $r=array(array('id'=>'1',"name"=>"{$kgname}"),array('id'=>3,'name'=>'RMB'));
                $this->assign('username',$_GET['username']);
                $this->assign('type',$r);
                $this->display('./Tpl/Admin/cz.html');
            }
        }
        /**
         * 充值虚拟币列表
         */
        public function chongzhi_xnb_list(){
            if(!empty($_POST['uname'])){
                $user=M("User")->where("username='{$_POST['uname']}'")->find();
                $where['t_chongzhi.uid']=$user['id'];
            }
          
            $Chongzhi=M("Chongzhi");
            import('ORG.Util.Page');// 导入分页类
            $where['t_chongzhi.type']='xnb';
            $count      = $Chongzhi->where($where)->count();// 查询满足要求的总记录数
            $Page       = new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
            $show       = $Page->show();// 分页显示输出
            // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
            $list = $Chongzhi->where($where)->join("t_user on t_chongzhi.uid=t_user.id")->field("t_chongzhi.*,t_user.username")->order('t_chongzhi.add_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();
             
            $this->assign('list',$list);// 赋值数据集
            $this->assign('page',$show);// 赋值分页输出
            $this->display('./Tpl/Admin/Chongzhi_xnb_list.html');
        }
        
        public function chongzhi_rmb_list(){
            if(!empty($_POST['uname'])){
                $user=M("User")->where("username='{$_POST['uname']}'")->find();
                $where['t_chongzhi.uid']=$user['id'];
            }
        
            $Chongzhi=M("Chongzhi");
            import('ORG.Util.Page');// 导入分页类
            $where['t_chongzhi.type']='rmb';
            $count      = $Chongzhi->where($where)->count();// 查询满足要求的总记录数
            $Page       = new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
            $show       = $Page->show();// 分页显示输出
            // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
            $list = $Chongzhi->where($where)->join("t_user on t_chongzhi.uid=t_user.id")->field("t_chongzhi.*,t_user.username")->order('t_chongzhi.add_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();
             
            $this->assign('list',$list);// 赋值数据集
            $this->assign('page',$show);// 赋值分页输出
            $this->display('./Tpl/Admin/Chongzhi_rmb_list.html');
        }
}